import exceptions.RentalException;
import rental.DVD;
import junit.framework.TestCase;


public class TestDVD extends TestCase {
	DVD regular;
	DVD forKids;
	DVD newMovie;
	
	protected void setUp() throws Exception {
		regular = new DVD("regularMovie", DVD.REGULAR);
		forKids = new DVD("MovieForKids", DVD.FOR_KIDS);
		newMovie = new DVD("newMovie", DVD.NEW_MOVIE);
	}

	public void testDVD1() throws RentalException{
		DVD regular = new DVD("regularMovie", DVD.REGULAR);
		assertEquals("regularMovie", regular.getTitle());
		assertEquals(0, regular.getPriceCode());		
	}
	
	public void testDVD2() throws RentalException{
		DVD forKids = new DVD("newMovie", DVD.NEW_MOVIE);
		assertEquals("newMovie", forKids.getTitle());
		assertEquals(1, forKids.getPriceCode());		
	}
	
	public void testDVD3() throws RentalException{
		DVD forKids = new DVD("MovieForKids", DVD.FOR_KIDS);
		assertEquals("MovieForKids", forKids.getTitle());
		assertEquals(2, forKids.getPriceCode());		
	}
	
	public void testDVD4(){
		try {
			DVD failMovie = new DVD("failMovie", 5);
			fail("Should had thrown an exception.");
		} catch (RentalException e) {
			assertEquals("Price code must be between 0 and 2.", e.getMessage());
		}		
	}
	
	public void testDVD5(){
		try {
			DVD failMovie = new DVD("failMovie", -1);
			fail("Should had thrown an exception.");
		} catch (RentalException e) {
			assertEquals("Price code must be between 0 and 2.", e.getMessage());
		}		
	}
	
	public void testGetPriceCode(){
		assertEquals(0, regular.getPriceCode());
		assertEquals(2, forKids.getPriceCode());
		assertEquals(1, newMovie.getPriceCode());
	}
		
	public void testGetRentValue1() {
		try {
			regular.getRentValue(0);
			fail();
		} catch (RentalException e) {
			assertEquals("The days of rent must be at least one.", e.getMessage());
		}
				
	}
	
	public void testGetRentValue2() throws RentalException {
		assertEquals(2.0, regular.getRentValue(1));
		assertEquals(1.5, forKids.getRentValue(1));
		assertEquals(3.0, newMovie.getRentValue(1));
	}
	
	public void testGetRentValue3() throws RentalException {
		assertEquals(2.0, regular.getRentValue(1));
		assertEquals(2.0, regular.getRentValue(2));
	}
	
	public void testGetRentValue4() throws RentalException {
		assertEquals(3.5, regular.getRentValue(3));
		assertEquals(6.5, regular.getRentValue(5));
		assertEquals(14.0, regular.getRentValue(10));
		assertEquals(149.0, regular.getRentValue(100));
		assertEquals(1499.0, regular.getRentValue(1000));
	}
	
	public void testGetRentValue5() throws RentalException {
		assertEquals(1.5, forKids.getRentValue(1));
		assertEquals(1.5, forKids.getRentValue(2));
		assertEquals(1.5, forKids.getRentValue(3));
	}
	
	public void testGetRentValue6() throws RentalException {
		assertEquals(3.0, forKids.getRentValue(4));
		assertEquals(4.5, forKids.getRentValue(5));
		assertEquals(12.0, forKids.getRentValue(10));
		assertEquals(147.0, forKids.getRentValue(100));
		assertEquals(1497.0, forKids.getRentValue(1000));
	}
	
	public void testGetRentValue7() throws RentalException {
		assertEquals(6.0, newMovie.getRentValue(2));
		assertEquals(12.0, newMovie.getRentValue(4));
		assertEquals(15.0, newMovie.getRentValue(5));
		assertEquals(30.0, newMovie.getRentValue(10));
		assertEquals(300.0, newMovie.getRentValue(100));
		assertEquals(3000.0, newMovie.getRentValue(1000));
	}

	public void testGetProgramPoints() {
		try {
			regular.getProgramPoints(0);
			fail();
		} catch (RentalException e) {
			assertEquals("The days of rent must be at least one.", e.getMessage());
		}
	}
	
	public void testGetProgramPoints2() throws RentalException {
		assertEquals(1, regular.getProgramPoints(1));
		assertEquals(1, regular.getProgramPoints(3));
		assertEquals(1, regular.getProgramPoints(5));
		assertEquals(1, regular.getProgramPoints(10));
		assertEquals(1, regular.getProgramPoints(100));
		assertEquals(1, regular.getProgramPoints(1000));
	}
	
	public void testGetProgramPoints3() throws RentalException {
		assertEquals(1, forKids.getProgramPoints(1));
		assertEquals(1, forKids.getProgramPoints(3));
		assertEquals(1, forKids.getProgramPoints(5));
		assertEquals(1, forKids.getProgramPoints(10));
		assertEquals(1, forKids.getProgramPoints(100));
		assertEquals(1, forKids.getProgramPoints(1000));
	}
	
	public void testGetProgramPoints4() throws RentalException {
		assertEquals(1, newMovie.getProgramPoints(1));
		assertEquals(2, newMovie.getProgramPoints(3));
		assertEquals(2, newMovie.getProgramPoints(5));
		assertEquals(2, newMovie.getProgramPoints(10));
		assertEquals(2, newMovie.getProgramPoints(100));
		assertEquals(2, newMovie.getProgramPoints(1000));
	}

	public void testGetClassification() {
		String packageName = "rental.";
		assertEquals(packageName+"RegularClassification", regular.getClassification().getClass().getName());
		assertEquals(packageName+"NewMovieClassification", newMovie.getClassification().getClass().getName());
		assertEquals(packageName+"ForKidsClassification", forKids.getClassification().getClass().getName());
	}

	public void testGetMsg() {
		assertEquals("This is a new movie. " +
				"Please check the classification in the back cover.", newMovie.getMsg());
		assertEquals("Movie recommended for all ages.", forKids.getMsg());
		assertEquals("Please check the classification in the back cover.", regular.getMsg());
	}

}
